home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4413 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Basic Question on SWITCH
  5. Date: Sun, 04 Feb 96 13:36:03 GMT
  6. Organization: none
  7. Message-ID: <823440963snz@genesis.demon.co.uk>
  8. References: <4e4cu4$95f@vixen.cso.uiuc.edu> <4e8p6m$n8q@ns.RezoNet.NET> <TANMOY.96Jan26162346@qcd.lanl.gov> <4ehfuj$166g@ns.RezoNet.NET>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4ehfuj$166g@ns.RezoNet.NET> ray@ultimate-tech.com "Ray Dunn" writes:
  15.  
  16. >In referenced article, Tanmoy Bhattacharya says...
  17. >>
  18. >>In article <3108ED49.987@cmt.lpr.mail.carel.fi> Ari Lukumies
  19. >><aril@cmt.lpr.mail.carel.fi> writes: 
  20. >><snip>
  21. >>           if (strchr("0123456789", a))
  22. >>                   ... /* It was a digit, do something */
  23. >>
  24. >>A special case for digits:
  25. >>
  26. >>if ((unsigned)(a-'0')<10)
  27.  
  28. That's better written as:
  29.  
  30.   if ((unsigned)a-'0'<10)
  31.  
  32. >>   /* It _is_ a digit, do something */
  33. >>
  34. >>But then what is wrong with isdigit?
  35.  
  36. As a curiosity:
  37.  
  38. #define isdigit(ch) ((unsigned)+(ch)-'0'<10)
  39.  
  40. is a portable definition of isdigit.
  41.  
  42. >Indeed.  In the general case there is no guarantee that all the digits 
  43. >are consecutive as they are in ASCII, so the use of isdigit is the only 
  44. >portable way to go, although the strchr example works fine too, if 
  45. >slowly.
  46.  
  47. As others have noted the standard makes these guarantees for digits.
  48.  
  49. >[As a matter of interest, MS 'C' uses a character table with bits 
  50. >defining all the various character types.  isdigit etc. uses this 
  51. >table. MS provides profiling functions which allows the customization 
  52. >of this table]
  53.  
  54. There are a number of aspects of the is*() functions which the standard
  55. makes locale-specific. However none of these apply to isdigit() which is
  56. not locale specific. Changing the 'is a digit' bits in the table is likely
  57. to mess up a lot of software that depends on them (and that probably includes
  58. the standard library). So maybe there is a use for as isdigit type macro
  59. defined as above.
  60.  
  61. -- 
  62. -----------------------------------------
  63. Lawrence Kirby | fred@genesis.demon.co.uk
  64. Wilts, England | 70734.126@compuserve.com
  65. -----------------------------------------
  66.